function isValidEmailAddress(emailAddress) 
{
	var pattern = new RegExp(/^[+a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i);
	return pattern.test(emailAddress);
}

jQuery(document).ready(function()
{
	
	$('#template-step2').hide();
	
	$('#btn-support-step1').click(function(){
		
		var step1 = $('#seo-support-step1').val();
		
		var mflag = '';
		
		if(step1.length<1 || step1.length>250)
		{
			mflag = '*';
			$('#seo-support-name').addClass("show-error");
		}
		else
			$('#seo-support-name').removeClass("show-error");
		
		if(mflag!='')
		{
			alert("Điền thông tin website.");
			return false;
		}
		else
		{		
			$('#seo-support-website').val(step1);
			
			$('#template-step1').hide();
			$('#template-step2').show();
		}
		});
	
	$('#btn-support-step2').click(function(){
		
		var website = $('#seo-support-website').val();
		var name	= $('#seo-support-name').val();
		var email	= $('#seo-support-email').val();
		var phone	= $('#seo-support-phone').val();
		var cb		= $('#cb-support').attr('checked')?true:false;
		var surl 	= $("#support-website-url").val();
		
		var mflag = '';
		
		if(name.length<1 || name.length>250)
		{
			mflag = '*';
			$('#seo-support-name').addClass("show-error");
		}
		else
			$('#seo-support-name').removeClass("show-error");
		//================
		if(email.length<1 || email.length>250 || !isValidEmailAddress(email))
		{
			mflag = '*';
			$('#seo-support-email').addClass("show-error");
		}
		else
			$('#seo-support-email').removeClass("show-error");
		
		//================
		if(phone.length<1 || phone.length>250)
		{
			mflag = '*';
			$('#seo-support-phone').addClass("show-error");
		}
		else
			$('#seo-support-phone').removeClass("show-error");
		
		if(mflag!='')
		{
			alert("Điền đầy đủ thông tin yêu cầu.");
			return false;
		}
		else
		{
			// Send data email
			var something = {'supportName': name,'supportEmail': email,'supportPhone':phone,'supportWebsite':website,'supportCheckbox':cb,'server-request':surl };
					
			var msurl = surl;
			surl += "/ajax-process";
			
			$.ajax({ // ajax call starts
				type: "POST",
				url: surl, // JQuery loads serverside.php
				data: something,// Send value of the clicked button
				dataType: 'json', // Choosing a JSON datatype
				success: function(data) // Variable data contains the data we get from serverside
				{	
					//alert(data);
				}
			});
			
			alert("Cảm ơn bạn đã gửi yêu cầu,Chúng tôi sẽ liên hệ lại trong thời gian sớm nhất.");
			
			var delay = 1000; //Your delay in milliseconds

			setTimeout(function(){ window.location = msurl; }, delay);
			
			//return true; // keeps the page from not refreshing 
		}
		
	});
	
	
	
	//slide show
	$(".gallery:first a[rel^='prettyPhoto']").prettyPhoto({animation_speed:'normal',slideshow:10000, autoplay_slideshow: false});
	//$(".gallery:gt(0) a[rel^='prettyPhoto']").prettyPhoto({animation_speed:'fast',slideshow:10000, hideflash: true});
	
	
	// validate form contact
	
	$('#btn-send-contact-data').click(function()
	{
		var sname 	= $("#txt-name").val();
		var semail 	= $("#txt-email").val();
		var sphone 	= $("#txt-phone").val();
		var swebsite = $("#txt-website").val();
		var smessage = $("#txt-message").val();
		var scontact = $("#txt-contact-style").val();
		
		var surl 	= $("#txt-website-url").val();
	
			
		var mflag = '';
		
		if(sname.length<1 || sname.length>250)
		{
			mflag = '*';
			$('#txt-name').addClass("show-error");
		}
		else
			$('#txt-name').removeClass("show-error");
		
		//-----------
		if(sphone.length<1 || sphone.length>30)
		{
			mflag = '*';
			$('#txt-phone').addClass("show-error");
		}
		else
			$('#txt-phone').removeClass("show-error");
		
		//-------
		if(semail.length<1 || semail.length>250 || !isValidEmailAddress(semail))
		{
			mflag = '*';
			$('#txt-email').addClass("show-error");
		}
		else
			$('#txt-email').removeClass("show-error");
		
		//-----
		if(smessage.length<1 || smessage.length>550)
		{
			mflag = '*';
			$('#txt-message').addClass("show-error");
		}
		else
			$('#txt-message').removeClass("show-error");
		
		
		if(mflag!='')
		{
			alert("Điền đầy đủ thông tin yêu cầu.");
			return false;
		}
		else
		{				
			// Send data email
			var something = {'customerName': sname,'customerEmail': semail,'customerPhone':sphone,'customerMessage':smessage,'customerWebsite':swebsite,'contact-style':scontact,'server-request':surl };
			var msurl = surl;
			surl += "/ajax-process";
			
			$.ajax({ // ajax call starts
				type: "POST",
				url: surl, // JQuery loads serverside.php
				data: something,// Send value of the clicked button
				dataType: 'json', // Choosing a JSON datatype
				success: function(data) // Variable data contains the data we get from serverside
				{	
					//alert(data);
				}
			});
			
			alert("Cảm ơn bạn đã gửi yêu cầu,Chúng tôi sẽ liên hệ lại trong thời gian sớm nhất.");
			
			var delay = 1000; //Your delay in milliseconds

			setTimeout(function(){ window.location = msurl; }, delay);
			
			//return true; // keeps the page from not refreshing 
			
		}	
		
		//return isValidateTextField(mArray);	
		
	});
	
	
	
	
	//------------------------------------------------------------------------------------
	// insert image fomenu
	$("#menu-item-2991,#menu-item-167").append('<span class="li-noactive"></span>');
	$("ul.sub-menu li a").append('<span></span>');
	

		// Slideshow 4
		  $("#slider1").responsiveSlides({
			auto: true,
			pager: true,
			nav: true,
			speed: 1000,
			maxwidth: 430,
			timeout: 10000, 
			namespace: "centered-btns"
		  });

		jQuery("#home-subheader-content ul li a").click(function(){



			jQuery('.home-service-bit.show').removeClass('show');



			jQuery(".home-service-bit." + jQuery(this).parent().attr("id")).addClass("show");







			jQuery("#home-subheader-content a.active").removeClass("active");



			jQuery(this).addClass("active");







			var parentId = jQuery(this).parent().attr("id");



			jQuery("#inside-bulb").fadeOut(500, function(){



				jQuery("#inside-bulb").removeClass().addClass(parentId).fadeIn(500);



			});



			return false;



		});







		jQuery("li.menu-item").has("ul.sub-menu").addClass("has-sub-menu").hoverIntent(function(){



			jQuery("ul.sub-menu", jQuery(this)).slideToggle(300);



		},



		function(){



			jQuery("ul.sub-menu", jQuery(this)).slideToggle(300);



		});







		jQuery("#cycle").cycle({timeout:10000});



		jQuery("#footer-chat > a").click(function(){

			olark('api.box.expand');

			return false;

		});



	});